﻿// //  ********************************************************************************
// //  Copyright (C) 2016 Sebastian Kenter. All rights reserved.
// // 
// //  Name    : MultiServerEngine | ServerFramework | ServerConfiguration.cs
// //  Created : 2016 - 02 - 16 20:53
// //  Modified: 2016 - 02 - 20 12:32
// //  ********************************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using ServerFramework.Implementation.Database.Domain;
using ServerFramework.Interfaces.Configuration;
using TypeDefs;

namespace ServerFramework.Implementation.Configuration
{
    [DataContract]
    public class ServerConfiguration : IServerConfiguration
    {
        [DataMember]
        public string IpAddress { get; set; }

        [DataMember]
        public int? TcpPort { get; set; }

        [DataMember]
        public int? UdpPort { get; set; }

        [DataMember]
        public bool IsMasterServer { get; set; }

        [DataMember]
        public int ConnectRetryInterval { get; set; }

        [DataMember]
        public int MaxRetries { get; set; }

        [DataMember]
        public Dictionary<HandlerTypes, List<OperationCodes>> HandledOperations { get; set; }

        [DataMember]
        public string MasterIpAddress { get; set; }

        [DataMember]
        public int MasterPort { get; set; }

        [DataMember]
        public string ServerName { get; set; }

        public ServerConfiguration(IList<Parameter_T> parameters)
        {
            MasterIpAddress = parameters.Single(c => c.Parkey == "IPAddress").Parvalue;
            MasterPort = Convert.ToInt32(parameters.Single(c => c.Parkey == "MasterUDPPort").Parvalue);
            IsMasterServer = Convert.ToBoolean(parameters.Single(c => c.Parkey == "IsMasterServer").Parvalue);
            ConnectRetryInterval = Convert.ToInt32(parameters.Single(c => c.Parkey == "ConRetInt").Parvalue);
            MaxRetries = Convert.ToInt32(parameters.Single(c => c.Parkey == "MaxRetries").Parvalue);
            ServerName = parameters.Single(c => c.Parkey == "ServerName").Parvalue;
            HandledOperations = new Dictionary<HandlerTypes, List<OperationCodes>>();
        }
    }
}
